package com.example.studentcompetitionplatform.service.impl;

import com.example.studentcompetitionplatform.entity.CompetitionArchives;
import com.example.studentcompetitionplatform.entity.Competitions;
import com.example.studentcompetitionplatform.mapper.JingSaiMapper;
import com.example.studentcompetitionplatform.service.IJingSaiService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class JingSaiService implements IJingSaiService {
   @Resource
   private JingSaiMapper jingSaiMapper;

    @Override
    public void insertC(Competitions competitions) {
        Date startTime=new Date(2023 - 1900, 10, 11);
        Date endTime=new Date(2023 - 1900, 11, 11);
        competitions.setStartTime(startTime);
        competitions.setEndTime(endTime);
        jingSaiMapper.insertCompetitions(competitions);
    }

    @Override
    public Map<String, Object> page(Integer pageNum, Integer pageSize, Integer competitionId) {
        pageNum = (pageNum - 1) * pageSize;
        if (competitionId == 0) {
            competitionId = null;
        }
        List<Competitions> data = jingSaiMapper.selectPage(pageNum, pageSize, competitionId);
        Integer total = jingSaiMapper.findCompetitionTotal(competitionId);
        Map<String, Object> res = new HashMap<>();
        res.put("data", data);
        res.put("total", total);
        return res;
    }

    @Override
    public void deleteC(Competitions competitions) {
        jingSaiMapper.deleteCompetitions(competitions);
    }

    @Override
    public void editC(Competitions competitions) {
        jingSaiMapper.editCompetitions(competitions);
    }
}
